import React from 'react';
import CommonList from 'src/components/CommonLists/list';
import services from 'src/services/api';
import { Tooltip } from 'antd';
import { MODEL_VAR_TYPE } from 'src/utils/constant'

class FieldList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'field';
    this.needOperateColumn = false;
    this.state = {
      applications: [],
      events: []
    };
  }

  // 删除时的参数
  getDeleteParam = record => {
    return { field_id: record.field_id };
  };

  componentDidMount() {
    this.getEventCodeList(this.props.queryTableParams.app_id);
  }

  refreshTableFilter = params => {
    this.props.refreshTableFilter && this.props.refreshTableFilter(params);
    this.getEventCodeList(params.app_id);
    this.props.refreshTableFilter({ ...params, ...{ event_id: '' } });
  };

  getEventCodeList = id => {
    services.event.getEventCodeList({ app_id: id || '' }).then(res => {
      if (res.code === 0) {
        this.setState({
          events: res.data
        });
      }
    });
  };

  getColumn = () => {
    return [
      {
        title: '字段/指标名称',
        key: 'var_name',
        dataIndex: 'var_name',
        ellipsis: true,
        width: 160,
        render: (text, record) => {
          return (
            <Tooltip title={text} placement='topLeft'>
              <div className='overflowtext' style={{ width: '100%' }}>
                {text}
              </div>
            </Tooltip>
          );
        }
      },

      {
        title: '字段/指标Code',
        key: 'var_code',
        dataIndex: 'var_code',
        ellipsis: true,
        render: (text, record) => {
          return (
            <Tooltip title={text} placement='topLeft'>
              <div className='overflowtext' style={{ width: '100%' }}>
                {text}
              </div>
            </Tooltip>
          );
        }
      },
      {
        title: '类型',
        key: 'var_type',
        dataIndex: 'var_type',
        ellipsis: true,
        render: (text, record) => {
          return <>{MODEL_VAR_TYPE[text]}</>;
        }
      }
    ];
  };
}

export default FieldList;
